<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<script type="text/javascript">
if($("#t_funPermission").val() == "N"){
	setFunPermission(null);
}

$('#roleFunForm').find('#role_fun_action_all_read').on('ifChanged', function(e) {
	var checked = $(this).is(':checked');
	if (checked){
		$('#roleFunForm').find('input[name="funRead"]').iCheck('check');
	} else {
		$('#roleFunForm').find('input[name="funRead"]').iCheck('uncheck');
	}
});
$('#roleFunForm').find('#role_fun_action_all_write').on('ifChanged', function(e) {
	var checked = $(this).is(':checked');
	if (checked){
		$('#roleFunForm').find('input[name="funWrite"]').iCheck('check');
	} else {
		$('#roleFunForm').find('input[name="funWrite"]').iCheck('uncheck');
	}
});

function savePermissionSet() {
	$('#roleFunForm').isValid(function(v) {
		if(v){
			var url = 'role/savePermission.do';
			var data = $('#roleFunForm').serialize();
			var successCallBack = function(result){
				$('#roleFunForm').alertmsg('info', result.message);
			}
			var failCallBack = null;
			var errorCallBack = null;
			myAjax(url, data, true, successCallBack, failCallBack, errorCallBack);
		}
	});
}

function setFunPermission(_this) {
	var funpermit = $("#t_funPermission").val();
	if(funpermit == "R"){
		$("#role_fun_action_all_read").iCheck('enable');
		$("#role_fun_action_all_write").iCheck('enable');
		$('#roleFunForm').find('input[name="funRead"]').iCheck('enable');
		$('#roleFunForm').find('input[name="funWrite"]').iCheck('enable');
		$("#role_fun_action_all_read").iCheck('check');
		$("#role_fun_action_all_write").iCheck('uncheck');
		$('#roleFunForm').find('input[name="funWrite"]').iCheck('uncheck');
	} else if (funpermit == "RW") {
		$("#role_fun_action_all_read").iCheck('enable');
		$("#role_fun_action_all_write").iCheck('enable');
		$('#roleFunForm').find('input[name="funRead"]').iCheck('enable');
		$('#roleFunForm').find('input[name="funWrite"]').iCheck('enable');
		$("#role_fun_action_all_read").iCheck('check');
		$("#role_fun_action_all_write").iCheck('check');
	} else {
		$("#role_fun_action_all_read").iCheck('uncheck');
		$("#role_fun_action_all_write").iCheck('uncheck');
		$("#role_fun_action_all_read").iCheck('disable');
		$("#role_fun_action_all_write").iCheck('disable');
		$('#roleFunForm').find('input[name="funRead"]').iCheck('disable');
		$('#roleFunForm').find('input[name="funWrite"]').iCheck('disable');
	}
}
</script>
<div class="bjui-pageContent" style="padding-bottom:0px;overflow:auto;">
	<input type="hidden" name="roleSn" value="${roleSn}">
	<input type="hidden" name="funSn" value="${funPermission.funSn}">
	<table class="table table-condensed" width="100%" cellpadding="5px">
		<tbody>
			<tr height="29px">
                <td style="width: 100px;">
                    <label class="control-label x100">功能菜单权限：</label>
                </td>
                <td colspan="3" style="width: 500px; text-align: left">
                    <select name="funPermission" id="t_funPermission" data-toggle="selectpicker" data-width="500" onchange="setFunPermission(this);">
                      	<option value="N" <c:if test='${funPermission.funPermission=="N"}'>selected="selected"</c:if>>无权限</option>
                      	<option value="R" <c:if test='${funPermission.funPermission=="R"}'>selected="selected"</c:if>>只读</option>
                      	<option value="RW" <c:if test='${funPermission.funPermission=="RW"}'>selected="selected"</c:if>>读写</option>
                    </select>
                </td>
			</tr>
			<tr height="29px">
                <td style="width: 100px;">
                    <label class="control-label x100">功能编号：</label>
                </td>
                <td colspan="3" style="width: 500px; text-align: left">
                    <lable style="vertical-align: middle;">${funPermission.funId }</lable>
                </td>
			</tr>
			<tr height="29px">
                <td style="width: 100px;">
                    <label class="control-label x100">功能名称：</label>
                </td>
                <td colspan="3" style="width: 500px; text-align: left">
                    <lable style="vertical-align: middle;">${funPermission.funName }</lable>
                </td>
			</tr>
			<tr height="29px">
                <td style="width: 100px;">
                    <label class="control-label x100">上级功能编号：</label>
                </td>
                <td colspan="3" style="width: 500px; text-align: left">
                    <lable style="vertical-align: middle;">${funPermission.parentFunId }</lable>
                </td>
			</tr>
			<tr height="29px">
                <td style="width: 100px;">
                    <label class="control-label x100">显示顺序：</label>
                </td>
                <td colspan="3" style="width: 500px; text-align: left">
                    <lable style="vertical-align: middle;">${funPermission.funIndex }</lable>
                </td>
			</tr>
			<tr height="29px">
                <td style="width: 100px;">
                    <label class="control-label x100">连接地址：</label>
                </td>
                <td colspan="3" style="width: 500px; text-align: left">
                    <lable style="vertical-align: middle;">${funPermission.linkPage }</lable>
                </td>
			</tr>
			<tr height="29px">
                <td style="width: 100px;">
                    <label class="control-label x100"><input type="checkbox" data-toggle="icheck" data-label="读权限：" id="role_fun_action_all_read"></label>
                </td>
                <td colspan="3" style="width: 500px; text-align: left">
                    <ul style='margin-top: 10px;margin-bottom: 10px;'>
                    <c:forEach items="${funPermission.funReadList}" var="funRead" >
                    	<li style='float:left;margin-bottom: 10px;'>
                    		<div style="width:100px;"><input type="checkbox" id="role_fun_read_${funRead.funActionSn}" name="funRead" value="${funRead.funActionSn}" data-toggle="icheck" data-label="${funRead.actionName}" <c:if test="${funRead.selected==true}">checked</c:if>></div>
                    	</li>
                    </c:forEach>
                    </ul>
                </td>
			</tr>
			<tr height="29px">
                <td style="width: 100px;">
                    <label class="control-label x100"><input type="checkbox" data-toggle="icheck" data-label="写权限：" id="role_fun_action_all_write"></label>
                </td>
                <td colspan="3" style="width: 500px; text-align: left">
                    <ul style='margin-top: 10px;margin-bottom: 10px;'>
                    <c:forEach items="${funPermission.funWriteList}" var="funWrite" >
                    	<li style='float:left;margin-bottom: 10px;'>
                    		<div style="width:100px;"><input type="checkbox" id="role_fun_write_${funWrite.funActionSn}" name="funWrite" value="${funWrite.funActionSn}" data-toggle="icheck" data-label="${funWrite.actionName}" <c:if test="${funWrite.selected==true}">checked</c:if>></div>
                    	</li>
                    </c:forEach>
                    </ul>
                </td>
			</tr>
			<tr height="29px">
                <td style="width: 100px;">
                    <label class="control-label x100">数据权限类型：</label>
                </td>
                <td style="width: 200px; text-align: left">
                    <select name="dataAuthType" id="t_dataAuthType" data-toggle="selectpicker" data-width="190">
                    <c:if test='${empty dataPermission}'>
                    	<option value="" selected="selected">无限制</option>
                    	<c:forEach var="dataAuthType" items="${dataAuthTypes}">
                    	<option value="${dataAuthType.id}">${dataAuthType.typeName}</option>
                    	</c:forEach>
                    </c:if>
                    <c:if test='${not empty dataPermission}'>
                      	<option value="">无限制</option>
                      	<c:forEach var="dataAuthType" items="${dataAuthTypes}">
                      		<c:choose>
                      			<c:when test="${dataAuthType.id == dataPermission.dataAuthTypeId}">
                    	<option value="${dataAuthType.id}" selected="selected">${dataAuthType.typeName}</option>
                      			</c:when>
                      			<c:otherwise>
                      	<option value="${dataAuthType.id}">${dataAuthType.typeName}</option>
                      			</c:otherwise>
                      		</c:choose>
                    	</c:forEach>
                    </c:if>
                    </select>
                </td>
                
                <td style="width: 100px;">
                    <label class="control-label x100">数据权限对象：</label>
                </td>
                <td style="width: 200px; text-align: left">
                    <select name="dataAuthObject" id="t_dataAuthObject" data-toggle="selectpicker" data-width="190">
                    <c:if test='${empty dataPermission}'>
                    	<option value="" selected="selected">无限制</option>
                    	<c:forEach var="dataAuthObject" items="${dataAuthObjects}">
                    	<option value="${dataAuthObject.id}">${dataAuthObject.objectName}</option>
                    	</c:forEach>
                    </c:if>
                    <c:if test='${not empty dataPermission}'>
                      	<option value="">无限制</option>
                      	<c:forEach var="dataAuthObject" items="${dataAuthObjects}">
                      		<c:choose>
                      			<c:when test="${dataAuthObject.id == dataPermission.dataAuthObjectId}">
                    	<option value="${dataAuthObject.id}" selected="selected">${dataAuthObject.objectName}</option>
                      			</c:when>
                      			<c:otherwise>
                      	<option value="${dataAuthObject.id}">${dataAuthObject.objectName}</option>
                      			</c:otherwise>
                      		</c:choose>
                    	</c:forEach>
                    </c:if>
                    </select>
                </td>
			</tr>
		</tbody>
	</table>
</div>
<div class="bjui-pageFooter">
	<ul>
		<li><button type="button" class="btn btn-default save" data-icon="save"
				onclick="savePermissionSet();">保存</button></li>
	</ul>
</div>